//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<CTexture2D10.h>
///	@path	~/src/graphics/dx10/
///	@date	2008/12/20
///	@desc	.

#include "xeres.h"

#include "graphics/ITexture.h"
#include "graphics/dx10/CDevice10.h"

namespace xeres {

	/*!
		\class	CTexture2D10
		\brief	Base implementation of texture in DX 10.
	*/
	class CTexture2D10 : public ITexture
	{
	public:

		/// \ctor
		CTexture2D10( ID3D10Texture2D * pTexture10 );

		/// \dtor
		virtual ~CTexture2D10( void );

		DECL_IOBJECT_CLASS( CTexture2D10 , ITexture );

	public:

	//@ interface

		/// \impl
		virtual bool OnLostDevice( void );

		/// \impl
		virtual bool OnResetDevice( RefWeak<IDevice> device );

		/// \impl
		virtual TextureType GetType( void );

		/// \impl
		virtual DXFormat GetFormat( void );

		/// \impl
		virtual Pair<int> GetSize( void );

		/// \impl
		virtual size_t GetDepth( void );

		/// \impl
		virtual bool IsWritable( void );

		/// \impl
		virtual bool IsReadable( void );

		/// \impl
		virtual bool Map( uint sub , ResourceMap& data );

		/// \impl
		virtual bool ReadBack( uint sub , ResourceMap& data , bool readonly );

		/// \impl
		virtual bool Unmap( uint sub );

		/// \impl
		virtual bool Update( uint sub , const Box<uint>& size , const byte * data , uint row_pitch , uint depth_pitch );

		/// \impl
		virtual IUnknown * GetTextureInterface( void );

	//@ local
		
		///	\brief		Get texture interface.
		ID3D10Texture2D * GetTexture( void ) const { return m_pTexture10; }

	protected:

	//@ data

		ID3D10Texture2D *		m_pTexture10;
		D3D10_TEXTURE2D_DESC	m_desc;
	};

	/*!
		\class	CShaderTexture2D10
		\brief	Texture used in shader context.
	*/
	class CShaderTexture2D10 : public CTexture2D10
	{
	public:

		/// \ctor
		CShaderTexture2D10( ID3D10Texture2D * tex , ID3D10ShaderResourceView * pView );

		/// \dtor
		virtual ~CShaderTexture2D10( void );

		DECL_IOBJECT_CLASS( CShaderTexture2D10 , CTexture2D10 );

	public:

	//@ interface

		/// \impl
		virtual IUnknown * GetTextureInterface( void );

	//@ local

		ID3D10ShaderResourceView * GetView( void ) const { return m_pView10; }

	protected:

		/// \brief	Get texture interface from shader view.
		static ID3D10Texture2D * GetTexFromView( ID3D10ShaderResourceView * view );

	//@ data
		ID3D10ShaderResourceView *		m_pView10;
	};

} // namespace xeres
